/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package zeroticket;

import java.util.List;
import javax.smartcardio.CardException;
import javax.smartcardio.CardTerminal;
import javax.smartcardio.TerminalFactory;

/**
 *
 * @author giovannirojas
 */
public class TerminalCardEMV {
    
    protected static CardTerminal cardTerminalSystem;

    public TerminalCardEMV() {
        cardTerminalSystem = null;
    }

    
    public void connectTerminal() throws DPIParseException {
        
        CardTerminal cardTerminal = null ;
        TerminalFactory terminalFactory = TerminalFactory.getDefault();

        try {
            List<CardTerminal> cardTerminalList = terminalFactory.terminals().list();
            if (cardTerminalList.size() > 0) {
                cardTerminal = cardTerminalList.get(0);
            } else {
                throw new  DPIParseException("No se detectó ningún lector de tarjetas ");
            }
        } catch (DPIParseException | CardException e) {
            throw new DPIParseException("Ocurió un error al hacer la conección con el lector. "+e);
            
        }
        
        cardTerminalSystem = cardTerminal;
    }

    public static CardTerminal getCardTerminalSystem() {
        return cardTerminalSystem;
    }
    
    

}
